export default function ({ app, redirect, route, store }) {
  if (!route.matched.length || route.fullPath === '/main' || route.fullPath === '/main/') {
    //不匹配
    if (app.$cookies.get('uid')) {
      //已登录
      redirect('/main/#/pm?tab=list&elTab=0')
    } else {
      //未登录
      redirect('/skb_login/')
    }
  } else {
    //匹配
    if (app.$cookies.get('uid')) {
      //已登录
      if (route.name === 'skb_login') {
        //首页
        redirect('/main/#/pm?tab=list&elTab=0')
      } else {
        //其他页
        store.commit('setUid', app.$cookies.get('uid'))
        store.commit('setGuid', app.$cookies.get('guid'))
        store.commit('setUname', app.$cookies.get('uname'))
        store.commit('setUphone', app.$cookies.get('uphone'))
        store.commit('setPureUserIds', app.$cookies.get('pure_user_ids') ? JSON.stringify(app.$cookies.get('pure_user_ids')) : '')
        store.commit('setTabs', app.$cookies.get('tabs') ? JSON.stringify(app.$cookies.get('tabs')) : '')
        store.commit('setProjectName', app.$cookies.get('projectName') ? JSON.stringify(app.$cookies.get('projectName')) : '')
        store.commit('setManager', app.$cookies.get('manager'))
        store.commit('setDemo', app.$cookies.get('demo'))
      }
    } else {
      //未登录
      if (route.name !== 'skb_login') {
        redirect('/skb_login/')
      }
    }
  }
}
